<template>
  <div class="app-container">
    <wise-crud ref="wise-crud" :urls="urls" :fields="fields" :handle="handle" @selection-change="handleSelectionChange">
      <template slot="outHandle">
        <el-col :span="3">
          <el-button v-permission="['superSysOpsAdmin']" type="danger" @click="batchRemove">批量删除</el-button>
        </el-col>
      </template>
    </wise-crud>
  </div>
</template>
<script>
import WiseCrud from '@/components/Crud/wiseCrud'
import { postHandle } from '@/api'
export default {
  name: 'LoginLogManage',
  components: { WiseCrud },
  data() {
    return {
      urls: {
        list: '/api/v1/welder-uac-second/login-log-comb/list',
        show: '/api/v1/welder-uac-second/login-log-comb/show/'
      },
      handle: [''],
      fields: [
        { type: 'selection', use: ['table'] },
        {
          label: '登录账号',
          prop: 'username',
          type: 'text',
          labelWidth: '130px',
          use: ['table', 'view', 'search']
        },
        {
          label: '用户名称',
          prop: 'userInformation',
          type: 'render',
          labelWidth: '130px',
          tableRender: (h, row, index) => {
            return h('div', row.userInformation ? row.userInformation.username : '')
          },
          viewRender: (h, item, object) => {
            return h('div', object.userInformation ? object.userInformation.username : '')
          },
          use: ['table', 'view', 'search']
        },
        /* {
    label: '用户IP',
    prop: 'ipAddress',
    type: 'text',
    maxlength: 20,
    labelWidth: '120px',
    use: ['table', 'view', 'search']
    },*/
        {
          label: '登陆时间',
          prop: 'ct',
          format: 'YYYY-MM-DD HH:mm:ss',
          type: 'date',
          labelWidth: '130px',
          use: ['table', 'view', 'search']
        },
        {
          label: '浏览器名称',
          prop: 'userAgent',
          type: 'text',
          maxlength: 20,
          labelWidth: '130px',
          use: ['table', 'view', 'search']
        },
        { label: '操作', type: 'handle', use: ['table'], handle: ['view'] }
      ],
      multipleSelection: []
    }
  },
  methods: {
    handleSelectionChange (val) {
      this.multipleSelection = val;
    },
    batchRemove () {
      if(!( this.multipleSelection&&  this.multipleSelection.length>0)) {
        this.$message.error('请选择要删除的数据');
        return false
      }
      this.$confirm('此操作将永久删除该文件, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        postHandle('/api/v1/welder-uac-second/login-log-comb/remove-batch', {
          d: {},
          obj: {
            dataIds: this.multipleSelection.map(item=>item.id)
          }
        }).then(res=>{
          this.$message({
            type: 'success',
            message: '删除成功!'
          });
          this.$refs['wise-crud'].handleSearch()
        }).catch(() => {
          this.$message({
            type: 'info',
            message: '删除失败'
          });
        });
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消删除'
        });
      });
    }
  }
}
</script>

  <style />
</template>
